package com.itheima.Array.DoublePointer;

/**
 * @Author: Ethan Yankang
 * @Program: code-random-recordings
 * @Date: 2024-07-28 18:39
 **/
public class BackspaceCompare {
    public boolean backspaceCompare(String s, String t) {
        return Compare(s).equals(Compare(t));
    }

    private String Compare(String str) {
        StringBuilder stringBuilder = new StringBuilder(str);
        StringBuilder stringBuilder1 = new StringBuilder();
        int len = stringBuilder.length();
        int i = 0;
        while (i < len) {
            char ch = stringBuilder.charAt(i);
            if (ch != '#') {
                stringBuilder1.append(ch);
            } else if (!stringBuilder1.isEmpty()) {
                stringBuilder1.deleteCharAt(stringBuilder1.length() - 1);
            }
            i++;
        }
        return stringBuilder1.toString();
    }
}

